#!/usr/bin/env python

import doctest, sys, pprint

if __name__ == "__main__":
    def usage():
        print """\
Usage:
   %(appname)s <module1> ... <moduleN>


""" % { "appname": sys.argv[ 0 ],
        }
    # usage()


    if len( sys.argv ) < 1:
        usage()

    pp = pprint.PrettyPrinter(indent=3)
    ret = 0
    for modname in sys.argv[ 1 : ]:
        print "Testing '%s' documentation:" % modname,
        try:
            module = __import__( modname )
            failed, tries = doctest.testmod( module )
            if failed > 0:
                print "\tFailed tests: %d/%d (%0.2f%%)" % \
                      ( failed, tries, float( failed ) / tries )
                ret += failed
            elif tries < 1:
                print "Warning: no tests found"
            else:
                print "Ok (%d tests)" % tries
        except ImportError:
            print "\n\tModule '%s' doesn't exists in:" % modname
            pp.pprint( sys.path )
    sys.exit( ret )
# endif __name__ == "__main__"
